package com.yl.auth.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yl.auth.model.entity.Bingshi;
import com.yl.auth.model.entity.Laoren;
import com.yl.auth.service.BingshiService;
import com.yl.auth.service.LaorenService;
import com.yl.common.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yl
 * @since 2023-06-17
 */
@RestController
@RequestMapping("/admin/auth/bingshi")
@Api(tags = "出入院管理-健康信息病史")
public class BingshiController {

    @Resource
    private BingshiService bingshiService;

    @Resource
    private LaorenService laorenService;

    @GetMapping("/getById/{id}")
    public Result getById(@PathVariable @ApiParam("老人id") Long id) {
        try {
            LambdaQueryWrapper<Bingshi> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(Bingshi::getLaorenId,id);
            Bingshi bingshi = bingshiService.getOne(wrapper);
            if(bingshi!=null) {
                String[] newBingShi = bingshi.getNewbingshi().split(",");
                String[] oldBingShi = bingshi.getOldbingshi().split(",");
                for (int i = 0; i < newBingShi.length; i++) {
                    System.out.println("00000000000000000000000000000000000000000000000"+newBingShi[i]);
                }
                for (int i = 0; i < oldBingShi.length; i++) {
                    System.out.println("---------------------------------------------"+oldBingShi[i]);
                }
                Laoren laoren = laorenService.getById(id);
                long count = bingshi.getJinshi() + bingshi.getXizao() + bingshi.getZhuangshi() +
                        bingshi.getRuce() + bingshi.getYidong() + bingshi.getRenzhi() + bingshi.getQingxu() +
                        bingshi.getShijue() + bingshi.getTingli() + bingshi.getChuanyi();
                if(count >=1 && count <= 15) {
                    laoren.setCareLevelId((long)1);
                    laorenService.updateById(laoren);
                }else if(count >=15 &&count <=25 ) {
                    laoren.setCareLevelId((long)2);
                    laorenService.updateById(laoren);
                }else {
                    laoren.setCareLevelId((long)3);
                    laorenService.updateById(laoren);
                }
                Map<String,Object> map = new HashMap<>();
                map.put("newBingShi",newBingShi);
                map.put("oldBingShi",oldBingShi);
                map.put("bingshi",bingshi);
                return Result.ok(map);
            }
        }catch (Exception e) {
            e.printStackTrace();
        }
        return Result.ok();
    }
}

